﻿/*********************************************************************
 版权所有: 版权所有(C) 2010 ,熙软研发部
 模块编号:  ContactsDO
 作    者:范徐超
 编写日期:2010-3-6
 审    核:
 审核日期:
 描    述:ContactsDO 通讯录联系人信息  数据访问类
...........................................................................
如果模块有修改，则每次修改添加以下注释(以系统上线后为基准)：

 *********************************************************************/

using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;

using Cisoft.IntegrationSystem.DataHelper;

namespace Cisoft.Cisoft3G.DAL
{
    /// <summary>
    /// 数据访问类ContactsDO。
    /// </summary>
    public class ContactsDO
    {
        public ContactsDO()
        { }
        #region  成员方法

        /// <summary>
        /// 得到最大ID
        /// </summary>
        public int GetMaxId()
        {
            return SQLServerHelper.GetMaxID("CT_ContactID", "CG_Contacts");
        }

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int CT_ContactID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from CG_Contacts");
            strSql.Append(" where CT_ContactID=@CT_ContactID ");
            SqlParameter[] parameters = {
					new SqlParameter("@CT_ContactID", SqlDbType.Int,4)};
            parameters[0].Value = CT_ContactID;

            return SQLServerHelper.Exists(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public void Add(Cisoft.Cisoft3G.Model.ContactsMO model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into CG_Contacts(");
            strSql.Append("CT_ContactID,CT_Name,CT_Sex,CT_Phone,CT_Mobile,CT_Mobile2,CT_Email,CT_PostCode,CT_Address,CT_Company,CT_CompanyAddress,CT_Department,CT_Duty,CT_QQ,CG_ContactGroupID_FK,CT_IsUser)");
            strSql.Append(" values (");
            strSql.Append("@CT_ContactID,@CT_Name,@CT_Sex,@CT_Phone,@CT_Mobile,@CT_Mobile2,@CT_Email,@CT_PostCode,@CT_Address,@CT_Company,@CT_CompanyAddress,@CT_Department,@CT_Duty,@CT_QQ,@CG_ContactGroupID_FK,@CT_IsUser)");
            SqlParameter[] parameters = {
					new SqlParameter("@CT_ContactID", SqlDbType.Int,4),
					new SqlParameter("@CT_Name", SqlDbType.NVarChar,50),
					new SqlParameter("@CT_Sex", SqlDbType.Int,4),
					new SqlParameter("@CT_Phone", SqlDbType.NVarChar,50),
					new SqlParameter("@CT_Mobile", SqlDbType.NVarChar,50),
					new SqlParameter("@CT_Mobile2", SqlDbType.NVarChar,50),
					new SqlParameter("@CT_Email", SqlDbType.NVarChar,50),
					new SqlParameter("@CT_PostCode", SqlDbType.NVarChar,50),
					new SqlParameter("@CT_Address", SqlDbType.NVarChar,50),
					new SqlParameter("@CT_Company", SqlDbType.NVarChar,50),
					new SqlParameter("@CT_CompanyAddress", SqlDbType.NVarChar,50),
					new SqlParameter("@CT_Department", SqlDbType.NVarChar,50),
					new SqlParameter("@CT_Duty", SqlDbType.NVarChar,50),
					new SqlParameter("@CT_QQ", SqlDbType.NVarChar,50),
					new SqlParameter("@CG_ContactGroupID_FK", SqlDbType.Int,4),
                    new SqlParameter("@CT_IsUser", SqlDbType.Int,4)};
            parameters[0].Value = model.CT_ContactID;
            parameters[1].Value = model.CT_Name;
            parameters[2].Value = model.CT_Sex;
            parameters[3].Value = model.CT_Phone;
            parameters[4].Value = model.CT_Mobile;
            parameters[5].Value = model.CT_Mobile2;
            parameters[6].Value = model.CT_Email;
            parameters[7].Value = model.CT_PostCode;
            parameters[8].Value = model.CT_Address;
            parameters[9].Value = model.CT_Company;
            parameters[10].Value = model.CT_CompanyAddress;
            parameters[11].Value = model.CT_Department;
            parameters[12].Value = model.CT_Duty;
            parameters[13].Value = model.CT_QQ;
            parameters[14].Value = model.CG_ContactGroupID_FK;
            parameters[15].Value = model.CT_IsUser;

            SQLServerHelper.ExecuteSql(strSql.ToString(), parameters);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int AddWithResult(Cisoft.Cisoft3G.Model.ContactsMO model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into CG_Contacts(");
            strSql.Append("CT_ContactID,CT_Name,CT_Sex,CT_Phone,CT_Mobile,CT_Mobile2,CT_Email,CT_PostCode,CT_Address,CT_Company,CT_CompanyAddress,CT_Department,CT_Duty,CT_QQ,CG_ContactGroupID_FK,CT_IsUser)");
            strSql.Append(" values (");
            strSql.Append("@CT_ContactID,@CT_Name,@CT_Sex,@CT_Phone,@CT_Mobile,@CT_Mobile2,@CT_Email,@CT_PostCode,@CT_Address,@CT_Company,@CT_CompanyAddress,@CT_Department,@CT_Duty,@CT_QQ,@CG_ContactGroupID_FK,@CT_IsUser)");
            SqlParameter[] parameters = {
					new SqlParameter("@CT_ContactID", SqlDbType.Int,4),
					new SqlParameter("@CT_Name", SqlDbType.NVarChar,50),
					new SqlParameter("@CT_Sex", SqlDbType.Int,4),
					new SqlParameter("@CT_Phone", SqlDbType.NVarChar,50),
					new SqlParameter("@CT_Mobile", SqlDbType.NVarChar,50),
					new SqlParameter("@CT_Mobile2", SqlDbType.NVarChar,50),
					new SqlParameter("@CT_Email", SqlDbType.NVarChar,50),
					new SqlParameter("@CT_PostCode", SqlDbType.NVarChar,50),
					new SqlParameter("@CT_Address", SqlDbType.NVarChar,50),
					new SqlParameter("@CT_Company", SqlDbType.NVarChar,50),
					new SqlParameter("@CT_CompanyAddress", SqlDbType.NVarChar,50),
					new SqlParameter("@CT_Department", SqlDbType.NVarChar,50),
					new SqlParameter("@CT_Duty", SqlDbType.NVarChar,50),
					new SqlParameter("@CT_QQ", SqlDbType.NVarChar,50),
					new SqlParameter("@CG_ContactGroupID_FK", SqlDbType.Int,4),
					new SqlParameter("@CT_IsUser", SqlDbType.Int,4)};
            parameters[0].Value = model.CT_ContactID;
            parameters[1].Value = model.CT_Name;
            parameters[2].Value = model.CT_Sex;
            parameters[3].Value = model.CT_Phone;
            parameters[4].Value = model.CT_Mobile;
            parameters[5].Value = model.CT_Mobile2;
            parameters[6].Value = model.CT_Email;
            parameters[7].Value = model.CT_PostCode;
            parameters[8].Value = model.CT_Address;
            parameters[9].Value = model.CT_Company;
            parameters[10].Value = model.CT_CompanyAddress;
            parameters[11].Value = model.CT_Department;
            parameters[12].Value = model.CT_Duty;
            parameters[13].Value = model.CT_QQ;
            parameters[14].Value = model.CG_ContactGroupID_FK;
            parameters[15].Value = model.CT_IsUser;

            return SQLServerHelper.ExecuteSql(strSql.ToString(), parameters);
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public void Update(Cisoft.Cisoft3G.Model.ContactsMO model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update CG_Contacts set ");
            strSql.Append("CT_Name=@CT_Name,");
            strSql.Append("CT_Sex=@CT_Sex,");
            strSql.Append("CT_Phone=@CT_Phone,");
            strSql.Append("CT_Mobile=@CT_Mobile,");
            strSql.Append("CT_Mobile2=@CT_Mobile2,");
            strSql.Append("CT_Email=@CT_Email,");
            strSql.Append("CT_PostCode=@CT_PostCode,");
            strSql.Append("CT_Address=@CT_Address,");
            strSql.Append("CT_Company=@CT_Company,");
            strSql.Append("CT_CompanyAddress=@CT_CompanyAddress,");
            strSql.Append("CT_Department=@CT_Department,");
            strSql.Append("CT_Duty=@CT_Duty,");
            strSql.Append("CT_QQ=@CT_QQ,");
            strSql.Append("CG_ContactGroupID_FK=@CG_ContactGroupID_FK,");
            strSql.Append("CT_IsUser=@CT_IsUser");
            strSql.Append(" where CT_ContactID=@CT_ContactID ");
            SqlParameter[] parameters = {
					new SqlParameter("@CT_ContactID", SqlDbType.Int,4),
					new SqlParameter("@CT_Name", SqlDbType.NVarChar,50),
					new SqlParameter("@CT_Sex", SqlDbType.Int,4),
					new SqlParameter("@CT_Phone", SqlDbType.NVarChar,50),
					new SqlParameter("@CT_Mobile", SqlDbType.NVarChar,50),
					new SqlParameter("@CT_Mobile2", SqlDbType.NVarChar,50),
					new SqlParameter("@CT_Email", SqlDbType.NVarChar,50),
					new SqlParameter("@CT_PostCode", SqlDbType.NVarChar,50),
					new SqlParameter("@CT_Address", SqlDbType.NVarChar,50),
					new SqlParameter("@CT_Company", SqlDbType.NVarChar,50),
					new SqlParameter("@CT_CompanyAddress", SqlDbType.NVarChar,50),
					new SqlParameter("@CT_Department", SqlDbType.NVarChar,50),
					new SqlParameter("@CT_Duty", SqlDbType.NVarChar,50),
					new SqlParameter("@CT_QQ", SqlDbType.NVarChar,50),
					new SqlParameter("@CG_ContactGroupID_FK", SqlDbType.Int,4),
					new SqlParameter("@CT_IsUser", SqlDbType.Int,4)};
            parameters[0].Value = model.CT_ContactID;
            parameters[1].Value = model.CT_Name;
            parameters[2].Value = model.CT_Sex;
            parameters[3].Value = model.CT_Phone;
            parameters[4].Value = model.CT_Mobile;
            parameters[5].Value = model.CT_Mobile2;
            parameters[6].Value = model.CT_Email;
            parameters[7].Value = model.CT_PostCode;
            parameters[8].Value = model.CT_Address;
            parameters[9].Value = model.CT_Company;
            parameters[10].Value = model.CT_CompanyAddress;
            parameters[11].Value = model.CT_Department;
            parameters[12].Value = model.CT_Duty;
            parameters[13].Value = model.CT_QQ;
            parameters[14].Value = model.CG_ContactGroupID_FK;
            parameters[15].Value = model.CT_IsUser;

            SQLServerHelper.ExecuteSql(strSql.ToString(), parameters);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public void Delete(int CT_ContactID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from CG_Contacts ");
            strSql.Append(" where CT_ContactID=@CT_ContactID ");
            SqlParameter[] parameters = {
					new SqlParameter("@CT_ContactID", SqlDbType.Int,4)};
            parameters[0].Value = CT_ContactID;

            SQLServerHelper.ExecuteSql(strSql.ToString(), parameters);
        }

        /// <summary>
        /// 删除一条数据,Where
        /// </summary>
        public void Delete(string strWhere)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from CG_Contacts ");
            if (!string.IsNullOrEmpty(strWhere))
            {
                strSql.Append(" where 1=1 and " + strWhere + " ");
            }

            SQLServerHelper.ExecuteSql(strSql.ToString(), null);
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Cisoft.Cisoft3G.Model.ContactsMO GetModel(int CT_ContactID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 CT_ContactID,CT_Name,CT_Sex,CT_Phone,CT_Mobile,CT_Mobile2,CT_Email,CT_PostCode,CT_Address,CT_Company,CT_CompanyAddress,CT_Department,CT_Duty,CT_QQ,CG_ContactGroupID_FK,CT_IsUser from CG_Contacts ");
            strSql.Append(" where CT_ContactID=@CT_ContactID ");
            SqlParameter[] parameters = {
					new SqlParameter("@CT_ContactID", SqlDbType.Int,4)};
            parameters[0].Value = CT_ContactID;

            Cisoft.Cisoft3G.Model.ContactsMO model = new Cisoft.Cisoft3G.Model.ContactsMO();
            DataSet ds = SQLServerHelper.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["CT_ContactID"].ToString() != "")
                {
                    model.CT_ContactID = int.Parse(ds.Tables[0].Rows[0]["CT_ContactID"].ToString());
                }
                model.CT_Name = ds.Tables[0].Rows[0]["CT_Name"].ToString();
                if (ds.Tables[0].Rows[0]["CT_Sex"].ToString() != "")
                {
                    model.CT_Sex = int.Parse(ds.Tables[0].Rows[0]["CT_Sex"].ToString());
                }
                model.CT_Phone = ds.Tables[0].Rows[0]["CT_Phone"].ToString();
                model.CT_Mobile = ds.Tables[0].Rows[0]["CT_Mobile"].ToString();
                model.CT_Mobile2 = ds.Tables[0].Rows[0]["CT_Mobile2"].ToString();
                model.CT_Email = ds.Tables[0].Rows[0]["CT_Email"].ToString();
                model.CT_PostCode = ds.Tables[0].Rows[0]["CT_PostCode"].ToString();
                model.CT_Address = ds.Tables[0].Rows[0]["CT_Address"].ToString();
                model.CT_Company = ds.Tables[0].Rows[0]["CT_Company"].ToString();
                model.CT_CompanyAddress = ds.Tables[0].Rows[0]["CT_CompanyAddress"].ToString();
                model.CT_Department = ds.Tables[0].Rows[0]["CT_Department"].ToString();
                model.CT_Duty = ds.Tables[0].Rows[0]["CT_Duty"].ToString();
                model.CT_QQ = ds.Tables[0].Rows[0]["CT_QQ"].ToString();
                if (ds.Tables[0].Rows[0]["CG_ContactGroupID_FK"].ToString() != "")
                {
                    model.CG_ContactGroupID_FK = int.Parse(ds.Tables[0].Rows[0]["CG_ContactGroupID_FK"].ToString());
                }
                if (ds.Tables[0].Rows[0]["CT_IsUser"].ToString() != "")
                {
                    model.CT_IsUser = int.Parse(ds.Tables[0].Rows[0]["CT_IsUser"].ToString());
                }
                return model;
            }
            else
            {
                return null;
            }
        }

        public Cisoft.Cisoft3G.Model.ContactsMO GetModel(string strWhere)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 CT_ContactID,CT_Name,CT_Sex,CT_Phone,CT_Mobile,CT_Mobile2,CT_Email,CT_PostCode,CT_Address,CT_Company,CT_CompanyAddress,CT_Department,CT_Duty,CT_QQ,CG_ContactGroupID_FK,CT_IsUser from CG_Contacts ");
            if (!string.IsNullOrEmpty(strWhere))
            {
                strSql.Append(" where " + strWhere);
            }
            //strSql.Append(" where CT_ContactID=@CT_ContactID ");
            //SqlParameter[] parameters = {
            //        new SqlParameter("@CT_ContactID", SqlDbType.Int,4)};
            //parameters[0].Value = CT_ContactID;

            Cisoft.Cisoft3G.Model.ContactsMO model = new Cisoft.Cisoft3G.Model.ContactsMO();
            DataSet ds = SQLServerHelper.Query(strSql.ToString(), null);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["CT_ContactID"].ToString() != "")
                {
                    model.CT_ContactID = int.Parse(ds.Tables[0].Rows[0]["CT_ContactID"].ToString());
                }
                model.CT_Name = ds.Tables[0].Rows[0]["CT_Name"].ToString();
                if (ds.Tables[0].Rows[0]["CT_Sex"].ToString() != "")
                {
                    model.CT_Sex = int.Parse(ds.Tables[0].Rows[0]["CT_Sex"].ToString());
                }
                model.CT_Phone = ds.Tables[0].Rows[0]["CT_Phone"].ToString();
                model.CT_Mobile = ds.Tables[0].Rows[0]["CT_Mobile"].ToString();
                model.CT_Mobile2 = ds.Tables[0].Rows[0]["CT_Mobile2"].ToString();
                model.CT_Email = ds.Tables[0].Rows[0]["CT_Email"].ToString();
                model.CT_PostCode = ds.Tables[0].Rows[0]["CT_PostCode"].ToString();
                model.CT_Address = ds.Tables[0].Rows[0]["CT_Address"].ToString();
                model.CT_Company = ds.Tables[0].Rows[0]["CT_Company"].ToString();
                model.CT_CompanyAddress = ds.Tables[0].Rows[0]["CT_CompanyAddress"].ToString();
                model.CT_Department = ds.Tables[0].Rows[0]["CT_Department"].ToString();
                model.CT_Duty = ds.Tables[0].Rows[0]["CT_Duty"].ToString();
                model.CT_QQ = ds.Tables[0].Rows[0]["CT_QQ"].ToString();
                if (ds.Tables[0].Rows[0]["CG_ContactGroupID_FK"].ToString() != "")
                {
                    model.CG_ContactGroupID_FK = int.Parse(ds.Tables[0].Rows[0]["CG_ContactGroupID_FK"].ToString());
                }
                if (ds.Tables[0].Rows[0]["CT_IsUser"].ToString() != "")
                {
                    model.CT_IsUser = int.Parse(ds.Tables[0].Rows[0]["CT_IsUser"].ToString());
                }
                return model;
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select CT_ContactID,CT_Name,CT_Sex,CT_Phone,CT_Mobile,CT_Mobile2,CT_Email,CT_PostCode,CT_Address,CT_Company,CT_CompanyAddress,CT_Department,CT_Duty,CT_QQ,CG_ContactGroupID_FK,CT_IsUser ");
            strSql.Append(" FROM CG_Contacts ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return SQLServerHelper.Query(strSql.ToString());
        }

        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ");
            if (Top > 0)
            {
                strSql.Append(" top " + Top.ToString());
            }
            strSql.Append(" CT_ContactID,CT_Name,CT_Sex,CT_Phone,CT_Mobile,CT_Mobile2,CT_Email,CT_PostCode,CT_Address,CT_Company,CT_CompanyAddress,CT_Department,CT_Duty,CT_QQ,CG_ContactGroupID_FK,CT_IsUser ");
            strSql.Append(" FROM CG_Contacts ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by " + filedOrder);
            return SQLServerHelper.Query(strSql.ToString());
        }

        /*
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            SqlParameter[] parameters = {
                    new SqlParameter("@tblName", SqlDbType.VarChar, 255),
                    new SqlParameter("@fldName", SqlDbType.VarChar, 255),
                    new SqlParameter("@PageSize", SqlDbType.Int),
                    new SqlParameter("@PageIndex", SqlDbType.Int),
                    new SqlParameter("@IsReCount", SqlDbType.Bit),
                    new SqlParameter("@OrderType", SqlDbType.Bit),
                    new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
                    };
            parameters[0].Value = "CG_Contacts";
            parameters[1].Value = "ID";
            parameters[2].Value = PageSize;
            parameters[3].Value = PageIndex;
            parameters[4].Value = 0;
            parameters[5].Value = 0;
            parameters[6].Value = strWhere;	
            return SQLServerHelper.RunProcedure("UP_GetRecordByPage",parameters,"ds");
        }*/

        #endregion  成员方法

        #region 返回姓名，根据条件
        public DataSet GetName(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select CT_Name ");
            strSql.Append(" FROM CG_Contacts ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return SQLServerHelper.Query(strSql.ToString());
        }
        #endregion

        #region 判断手机号码是否重复
        public int MobileIsExsist(string mobile)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select Count(*) ");
            strSql.Append(" FROM CG_Contacts ");
            strSql.Append(" WHERE CT_Mobile='" + mobile + "' ");
            return SQLServerHelper.GetSingle(strSql.ToString(), null);
        }

        public int MobileIsExsist(string mobileOld, string mobileNew)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select Count(*) ");
            strSql.Append(" FROM CG_Contacts ");
            strSql.Append(" WHERE CT_Mobile <>'" + mobileOld + "' and CT_Mobile='" + mobileNew + "' ");
            return SQLServerHelper.GetSingle(strSql.ToString(), null);
        }
        #endregion
        public DataSet GetListWithPage(int pageCurrent, int pageSize, string strWhere)
        {
            DataSet ds = new DataSet();
            SqlParameter[] parameters = {
                    new SqlParameter("@tbname", SqlDbType.VarChar,500),
                    new SqlParameter("@FieldKey", SqlDbType.VarChar,500),
                    new SqlParameter("@PageCurrent", SqlDbType.Int,4),
                    new SqlParameter("@PageSize", SqlDbType.Int,4),
                    new SqlParameter("@FieldShow", SqlDbType.VarChar,50),
                    new SqlParameter("@FieldOrder", SqlDbType.VarChar,500),
                    new SqlParameter("@Where", SqlDbType.VarChar,500),
                    new SqlParameter("@ItemCount", SqlDbType.Int,4),
                    new SqlParameter("@PageCount", SqlDbType.Int,4)
                    };
            parameters[0].Value = "CG_Contacts";
            parameters[1].Value = "CT_ContactID";
            parameters[2].Value = pageCurrent;
            parameters[3].Value = pageSize;
            parameters[4].Value = "";
            parameters[5].Value = "CT_ContactID desc";
            parameters[6].Value = strWhere;
            parameters[7].Direction = ParameterDirection.Output;
            parameters[8].Direction = ParameterDirection.Output;
            ds = SQLServerHelper.ExecuteStoredProcedure("sp_PageView", parameters);
            return ds;
        }


        public int GetListCount(int pageCurrent, int pageSize, string strWhere)
        {
            DataSet ds = new DataSet();
            SqlParameter[] parameters = {
                    new SqlParameter("@tbname", SqlDbType.VarChar,500),
                    new SqlParameter("@FieldKey", SqlDbType.VarChar,500),
                    new SqlParameter("@PageCurrent", SqlDbType.Int,4),
                    new SqlParameter("@PageSize", SqlDbType.Int,4),
                    new SqlParameter("@FieldShow", SqlDbType.VarChar,50),
                    new SqlParameter("@FieldOrder", SqlDbType.VarChar,500),
                    new SqlParameter("@Where", SqlDbType.VarChar,500),
                    new SqlParameter("@ItemCount", SqlDbType.Int,4),
                    new SqlParameter("@PageCount", SqlDbType.Int,4)
                    };
            parameters[0].Value = "CG_Contacts";
            parameters[1].Value = "CT_ContactID";
            parameters[2].Value = pageCurrent;
            parameters[3].Value = pageSize;
            parameters[4].Value = "";
            parameters[5].Value = "CT_ContactID desc";
            parameters[6].Value = strWhere;
            parameters[7].Direction = ParameterDirection.Output;
            parameters[8].Direction = ParameterDirection.Output;
            object obj = SQLServerHelper.ExecuteStoredProcedure("sp_PageView", parameters, "@ItemCount");
            return Convert.ToInt32(obj);
        }


        #region 三表查询,联系人和管理员关联
        public DataSet GetUserAndContact(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select * ");
            strSql.Append(" FROM CG_Contacts,CIS_User,CIS_UserInfo ");

            strSql.Append(" where ct_mobile = ui_phone");
            strSql.Append(" and ui_userid_fk = us_userid ");

            if (strWhere.Trim() != "")
            {
                strSql.Append(" and " + strWhere);
            }
            return SQLServerHelper.Query(strSql.ToString());
        }

        /// <summary>
        /// 获得用户列表
        /// </summary>
        /// <param name="pageCurrent"></param>
        /// <param name="pageSize"></param>
        /// <param name="strWhere"></param>
        /// <returns></returns>
        public DataSet GetUserLst(int pageCurrent, int pageSize, string strWhere)
        {
            DataSet ds = new DataSet();
            SqlParameter[] parameters = {
                    new SqlParameter("@tbname", SqlDbType.VarChar,500),
                    new SqlParameter("@FieldKey", SqlDbType.VarChar,500),
                    new SqlParameter("@PageCurrent", SqlDbType.Int,4),
                    new SqlParameter("@PageSize", SqlDbType.Int,4),
                    new SqlParameter("@FieldShow", SqlDbType.VarChar,50),
                    new SqlParameter("@FieldOrder", SqlDbType.VarChar,500),
                    new SqlParameter("@Where", SqlDbType.VarChar,500),
                    new SqlParameter("@ItemCount", SqlDbType.Int,4),
                    new SqlParameter("@PageCount", SqlDbType.Int,4)
                    };
            parameters[0].Value = "UsersAndContacts";
            parameters[1].Value = "CT_Mobile";
            parameters[2].Value = pageCurrent;
            parameters[3].Value = pageSize;
            parameters[4].Value = "";
            parameters[5].Value = "US_UserID desc";
            parameters[6].Value = strWhere;
            parameters[7].Direction = ParameterDirection.Output;
            parameters[8].Direction = ParameterDirection.Output;
            ds = SQLServerHelper.ExecuteStoredProcedure("sp_PageView", parameters);
            return ds;
        }

        /// <summary>
        /// 获得用户列表记录条数
        /// </summary>
        /// <param name="pageCurrent"></param>
        /// <param name="pageSize"></param>
        /// <param name="strWhere"></param>
        /// <returns></returns>
        public int GetUserLstCount(int pageCurrent, int pageSize, string strWhere)
        {
            DataSet ds = new DataSet();
            SqlParameter[] parameters = {
                    new SqlParameter("@tbname", SqlDbType.VarChar,500),
                    new SqlParameter("@FieldKey", SqlDbType.VarChar,500),
                    new SqlParameter("@PageCurrent", SqlDbType.Int,4),
                    new SqlParameter("@PageSize", SqlDbType.Int,4),
                    new SqlParameter("@FieldShow", SqlDbType.VarChar,50),
                    new SqlParameter("@FieldOrder", SqlDbType.VarChar,500),
                    new SqlParameter("@Where", SqlDbType.VarChar,500),
                    new SqlParameter("@ItemCount", SqlDbType.Int,4),
                    new SqlParameter("@PageCount", SqlDbType.Int,4)
                    };
            parameters[0].Value = "UsersAndContacts";
            parameters[1].Value = "CT_Mobile";
            parameters[2].Value = pageCurrent;
            parameters[3].Value = pageSize;
            parameters[4].Value = "";
            parameters[5].Value = "US_UserID desc";
            parameters[6].Value = strWhere;
            parameters[7].Direction = ParameterDirection.Output;
            parameters[8].Direction = ParameterDirection.Output;
            object obj = SQLServerHelper.ExecuteStoredProcedure("sp_PageView", parameters, "@ItemCount");
            return Convert.ToInt32(obj);
        }

        #endregion
    }
}

